package com.metro.demo.untils;//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//


import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import org.apache.commons.lang3.StringUtils;
import org.icepdf.core.pobjects.Document;

public class PDFToImage {
    private static float alpha = 0.5F;
    private static int positionWidth = 150;
    private static int positionHeight = 300;
    private static Font font = new Font("仿宋", 1, 26);
    private static Color color;

    static {
        color = Color.GRAY;
    }

    public PDFToImage() {
    }

    public static List<String> pdftoIamge(float zoom, String inputFile, String outputFile, String graphics) {
        List<String> list = null;
        Document document = null;

        try {
            list = new ArrayList(0);
            document = new Document();
            document.setFile(inputFile);
            float rotation = 0.0F;
            int maxPages = document.getPageTree().getNumberOfPages();

            for(int i = 0; i < maxPages; ++i) {
                BufferedImage bfimage = (BufferedImage)document.getPageImage(i, 1, 2, rotation, zoom);
                if (StringUtils.isNotBlank(graphics)) {
                    bfimage = setGraphics(bfimage, graphics);
                }

                ImageIO.write(bfimage, "jpg", new File(outputFile + i + ".jpg"));
                bfimage.flush();
                list.add(outputFile + i + ".jpg");
            }
        } catch (Exception var11) {
            var11.printStackTrace();
        }

        if (document != null) {
            document.dispose();
        }

        return list;
    }

    public static BufferedImage setGraphics(BufferedImage bfimage, String graphics) {
        Graphics2D g = bfimage.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.setColor(color);
        g.setFont(font);
        g.setComposite(AlphaComposite.getInstance(10, alpha));
        g.rotate(-0.5235987755982988D);
        g.drawString(graphics, 0, bfimage.getHeight() / 2 * 1);
        g.dispose();
        return bfimage;
    }
}
